<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>后台用户操作记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/layui/css/layui.css') }}" media="all">
    <link rel="stylesheet" href="{{ url_for('static',filename='layuiadmin/style/admin.css') }}" media="all">
</head>
<body>


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                     <form class="layui-form" style="padding-bottom: 10px">
                        <div class="layui-input-inline">
                            <input type="text" name="user_id" autocomplete="off"
                                   placeholder="用户手机号或用户名" class="layui-input">
                            <input type="hidden" name="status" autocomplete="off" class="layui-input" value="{{ 0 }}">
                        </div>

                        <div class="layui-input-inline " style="width: 90px">
                            <button class="layui-btn" id="searchEmailCompany" data-type="reload">
                                <i class="layui-icon" style="font-size: 20px; "></i> 搜索
                            </button>
                        </div>
                    </form>
                    <div class="layui-btn-group test-table-btn" style="margin-bottom: 10px;" id="data_bar"
                         lay-filter="data_bar">
{#                        <button type="button" class="layui-btn" lay-event="add">添加数据</button>#}
                    </div>

                    <table class="layui-hide" id="test-table" lay-filter="test-table"></table>

{#                    <script type="text/html" id="test-table-barDemo">#}
{#                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>#}
{#                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>#}
{#                    </script>#}
                </div>
            </div>
        </div>
    </div>
</div>


<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form " action="" lay-filter="dataFrm" id="dataFrm">

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">名称：</label>
                <div class="layui-input-block">
                    <label>
                        <input type="text" name="name" lay-verify="required" placeholder="请输入名称" autocomplete="off"
                               class="layui-input">
                    </label>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">图片链接：</label>
                <div class="layui-input-block">
                    <input type="text" name="image_url" lay-verify="required" placeholder="请输入图片地址" autocomplete="off"
                           class="layui-input">
                    <button type="button" class="layui-btn" id="upload_btn">上传图片</button>

                </div>

            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">跳转链接：</label>
                <div class="layui-input-block">
                    <input type="text" name="link_url" placeholder="请输入图片地址" autocomplete="off"
                           class="layui-input">
                    <button type="button" class="layui-btn" id="upload_btn2">上传图片</button>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-col-md10">
                <label class="layui-form-label">优先级：</label>
                <div class="layui-input-block">
                    <input type="text" name="priority" lay-verify="required|number" placeholder="请输入优先级" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>

        <input type="hidden" name="status" value="{{ status }}">
        <input type="hidden" name="user_id_" value="{{ user_id }}">
        <input type="hidden" name="id">


        <div class="layui-form-item" style="margin-top:40px; ">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="doSubmit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

        {##}
        {#        <div class="layui-form-item">#}
        {#            <div class="layui-inline">#}
        {#                <input type="hidden" name="id" autocomplete="off"#}
        {#                           class="layui-input">#}
        {#                <label class="layui-form-label">名称:</label>#}
        {#                <div class="layui-input-inline">#}
        {#                    <input type="text" name="name" lay-verify="required" autocomplete="off"#}
        {#                           class="layui-input">#}
        {#                </div>#}
        {#            </div>#}
        {##}
        {#            <div class="layui-col-lg6">#}
        {#                <label class="layui-form-label">名称：</label>#}
        {#                <div class="layui-input-block">#}
        {#                    <label>#}
        {#                        <input type="text" name="name" lay-verify="required" placeholder="" autocomplete="off"#}
        {#                               class="layui-input">#}
        {#                    </label>#}
        {#                </div>#}
        {#            </div>#}
        {##}
        {#            <div class="layui-inline">#}
        {#                <label class="layui-form-label">图片链接:</label>#}
        {#                <div class="layui-input-inline layui-col-md12">#}
        {#                    <input type="text" name="image_url" lay-verify="required|url" autocomplete="off"#}
        {#                           class="layui-input">#}
        {#                    <button type="button" class="layui-btn" id="upload_btn">上传图片</button>#}
        {#                </div>#}
        {#            </div>#}
        {#        </div>#}
        {#        <div class="layui-form-item">#}
        {#            <div class="layui-inline">#}
        {#                <label class="layui-form-label">跳转链接:</label>#}
        {#                <div class="layui-input-inline">#}
        {#                    <input type="text" name="link_url" autocomplete="off"#}
        {#                           class="layui-input">#}
        {#                </div>#}
        {#            </div>#}
        {#            <div class="layui-inline">#}
        {#                <label class="layui-form-label">优先级:</label>#}
        {#                <div class="layui-input-inline">#}
        {#                    <input type="text" name="priority" lay-verify="required|number" autocomplete="off"#}
        {#                           class="layui-input">#}
        {#                </div>#}
        {#            </div>#}
        {#        </div>#}
        {#        <div class="layui-form-item" style="margin-top:40px;">#}
        {#            <div class="layui-input-block">#}
        {#                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release"#}
        {#                        lay-filter="doSubmit" lay-submit="">提交#}
        {#                </button>#}
        {#                <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm layui-icon layui-icon-refresh">重置#}
        {#                </button>#}
        {#            </div>#}
        {#        </div>#}


    </form>
</div>
<!-- 添加和修改的弹出层结束 -->


<script src="{{ url_for('static',filename='layuiadmin/layui/layui.js') }}"></script>
<script>
    layui.config({
        base: '../../../static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form', 'upload'], function () {
        var admin = layui.admin;
        var table = layui.table;
        var upload = layui.upload;
        var $ = layui.jquery;

        var data_user_id = $("input[name='user_id_']").val();
        var tableIns = table.render({
            elem: '#test-table',
            {#toolbar: "#data_bar",#}
            url: '/cms/cms_record_info/?user_id='+data_user_id,
            cols: [[
                {field: 'id', title: 'ID', sort: true, align: 'center', hide: true},
                {field: 'admin_phone', title: '后台账户', sort: true, align: 'center'},
                {field: 'username', title: '前台用户', sort: true, align: 'center'},
                {field: 'user_phone', title: '前台手机号', sort: true, align: 'center'},
                {field: 'record', title: '操作内容', width: 500, align: 'center'},
                {field: 'ip', title: 'ip地址', sort: true, align: 'center'},
                {field: 'create_time', title: '创建时间', sort: true, align: 'center'},
                {#{align: 'center', fixed: 'right', title: '操作', toolbar: '#test-table-barDemo'}#}
            ]]
            , page: true
        });


        // 添加数据按钮事件
        $('.test-table-btn .layui-btn').on('click', function () {
            openAdd()
        });


        //监听工具条
        table.on('tool(test-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除么?', function (index) {
                    $.ajax({
                        url: '/cms/mall/d_banner/',
                        type: "POST",
                        data: data,
                        success: function (data) {
                            if (data['code'] == 200) {
                                //关闭弹框
                                layer.close(mainIndex);
                                //显示提示框
                                layer.msg("成功", {icon: 6});
                                tableIns.reload()
                            } else {
                                layer.msg(data['message'], {icon: 5});
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                openUpdate(data);
            }
        });


        var url;
        var mainIndex;

        //打开添加页面
        function openAdd() {
            mainIndex = layer.open({
                type: 1,
                title: '添加数据',
                content: $("#saveOrUpdateDiv"),
                area: ['600px', '450px'],
                success: function (index) {
                    //清空表单数据
                    $("#dataFrm")[0].reset();
                }
            });
        }

        //打开修改页面
        function openUpdate(data) {
            mainIndex = layer.open({
                type: 1,
                title: '修改数据',
                content: $("#saveOrUpdateDiv"),
                area: ['600px', '450px'],
                success: function (index) {
                    layui.form.val("dataFrm", data);
                }
            });
        }


        //保存
        layui.form.on("submit(doSubmit)", function (obj) {
            //序列化表单数据
            {#var params = $("#dataFrm").field();#}
            var data = obj.field;
            data['status'] = data_status;
            console.log(data);
            $.ajax({
                url: '/cms/mall/add_banner/',
                type: "POST",
                data: data,
                success: function (data) {
                    {#var json = JSON.parse(msg);#}
                    {#var returnCode = json.returnCode;#}
                    if (data['code'] == 200) {
                        //关闭弹框
                        layer.close(mainIndex);
                        //显示提示框
                        layer.msg("成功", {icon: 6});
                        console.log('成功了');
                        tableIns.reload()
                    } else {
                        layer.msg(data['message'], {icon: 6});
                    }
                }
            });

        });


        // 上传图片
        var imgInput = $("input[name='image_url']");
        upload.render({
            elem: '#upload_btn' //绑定元素
            , url: '/cms/cms_upload/' //上传接口
            , done: function (res) {
                if (res.code == 200) {
                    imgInput.val(res.data.url);
                } else {
                    layer.msg(res.message)
                }
            }
            , error: function () {
                layer.msg('上传失败')
            }
        });

        var linkInput = $("input[name='link_url']");
        upload.render({
            elem: '#upload_btn2' //绑定元素
            , url: '/cms/cms_upload/' //上传接口
            , done: function (res) {
                if (res.code == 200) {
                    linkInput.val(res.data.url);
                } else {
                    layer.msg(res.message)
                }
            }
            , error: function () {
                layer.msg('上传失败')
            }
        });

    });
</script>
</body>
</html>